use strict;
use warnings;

use File::Spec;
use FindBin;
use lib File::Spec->catfile($FindBin::RealBin, qw/.. lib/);
use Test::More;
use Test::Number::Delta within => 1e-3;
use Algorithm::LBFGS;

plan tests => 3;

use Lingua::EN::WSD::WebBased::Utils;

# test log_dirichlet

{
    my $x = [1/3, 1/3, 1/3];
    my $alpha = [1, 1, 1];

    delta_ok log_dirichlet($x, $alpha), 0.6931, qq/dirichlet: basic test/;

}

# test log_dirichlet_likelihood

{

    my $alpha = [1, 1, 1];
    my $vector_set = [
        [1/3, 1/3, 1/3],
        [1/2, 1/4, 1/4]
    ];

    delta_ok log_dirichlet_likelihood($alpha, $vector_set), 1.3863;

}

# test d_log_dirichlet_likelihood

{

    my $o = new Algorithm::LBFGS;
    my $alpha = [1, 1, 1];
    my $vector_set = [
        [1/3, 1/3, 1/3],
        [1/2, 1/4, 1/4]
    ];
    my $r = $o->fmin(build_lbfgs_cb($vector_set), [1, 1, 1], 'verbose');
    use Data::Dumper;
    diag Dumper $r;


}

# test combine_vectors

{
    my $v1 = {a => 1, b => 2, c => 3};
    my $v2 = {b => 1, e => 4};
    my $v3 = {a => 2, b => 1, g => 6};

    is_deeply
        combine_vectors($v1, $v2, $v3),
        {a => 3, b => 4, c => 3, e => 4, g => 6},
        qq/combine_vectors: basic test/;
}

